package cn.yj.frame.spring.anotation;

import cn.yj.frame.annotation.RpcService;
import cn.yj.frame.spring.RpcServiceBeanPostProcessor;
import cn.yj.register.RegisterConfig;
import cn.yj.register.RpcProperties;
import org.springframework.beans.BeansException;

/**
 * @author 永健
 * @since 2022-01-18 16:03
 */
public class RpcServiceAnnotationBeanHandlerProcessor implements RpcServiceBeanPostProcessor {

	private RpcProperties properties;

	public RpcServiceAnnotationBeanHandlerProcessor(RpcProperties properties) {
		this.properties = properties;
	}

	/**
	 * bean初始化好后，暴露出去，将其注册到注册中心
	 */
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		// 暴露接口
		RegisterConfig.getInstance().export(bean, beanName, properties.getProvider().getHost());
		return bean;
	}
}
